package com.yunpuvip.sachet.rest.controller.port;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.thoughtworks.xstream.core.ReferenceByIdMarshaller;
import com.yunpuvip.sachet.biz.entity.*;
import com.yunpuvip.sachet.biz.service.GiftInfoService;
import com.yunpuvip.sachet.biz.service.OrderService;
import com.yunpuvip.sachet.biz.service.SysparamService;
import com.yunpuvip.sachet.modular.constant.ApplicationConstant;
import com.yunpuvip.sachet.modular.constant.enumconstant.OrderStatus;
import com.yunpuvip.sachet.modular.constant.enumconstant.PayMethod;
import com.yunpuvip.sachet.modular.constant.enumconstant.PayStatus;
import com.yunpuvip.sachet.modular.constant.enumconstant.PayType;
import com.yunpuvip.sachet.modular.constant.response.ServerResponse;
import com.yunpuvip.sachet.modular.vo.rest.request.RechargeVo;
import com.yunpuvip.sachet.modular.vo.rest.request.UserPrepayVo;
import com.yunpuvip.sachet.rest.controller.common.RestBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.IdGenerator;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ auther wushaohong
 * @ date  2019/8/11
 **/
@RequestMapping("recharge")
@RestController
public class RechargeController extends RestBaseController {


    @Autowired
    private SysparamService sysparamService;

    @Autowired
    private OrderService orderService;

    @Autowired
    private GiftInfoService giftInfoService;
    /**
     * 获取赠送比例
     * @return
     */
    @RequestMapping("giftScale")
    public ServerResponse getGiftScale(){
        //获取赠送比例

        String sysparamVlaue = sysparamService.getSysparamVlaue(ApplicationConstant.GIFTSCALE);
        List<GiftInfo> giftInfoList = giftInfoService.getGiftInfo(null);
        Map<String, Object> map = dataMap("giftScale", sysparamVlaue);
        map.put("giftInfoList",giftInfoList);
        return ServerResponse.creatBySuccess(map);

    }

    /**
     * 用户充值
     * @return
     */
    @RequestMapping("userRecharge")
    public ServerResponse userRechangePack(@Valid RechargeVo rechargeVo){
        Integer id = getPlayer().getId();
        return ServerResponse.creatBySuccess(orderService.userRechagePack(id,rechargeVo));
    }


    /**
     * 用户下单,应该后面用于后台生成订单
     * @return
     */
    @RequestMapping("createOrder")
    public ServerResponse userPackOrder(@Valid RechargeVo rechargeVo){
        Integer id = getPlayer().getId();
        return ServerResponse.creatBySuccess(orderService.userOrderPack(id,rechargeVo));
    }

}
